﻿using UnityEngine;
using System.Collections;

public class AnimationEvent : SparkBehaviour {

    public bool receiveValueSetEvent = false;

    private Animator _animator;
    private Animator animator
    {
        get 
        {
            if (_animator == null)
            {
                _animator = GetComponent<Animator>();
                animator.logWarnings = false;
            }
            return _animator;
        }
    }

    void CastEventUpward(string eventName)
    {
        SendMessageUpwards(eventName, SendMessageOptions.DontRequireReceiver);
    }

    void CastEventDownward(string eventName)
    {
        SendMessage(eventName, SendMessageOptions.DontRequireReceiver);
    }

    void AniEventSetTrigger(object triggerName)
    {
        if(receiveValueSetEvent)
        animator.SetTrigger((string)triggerName);
    }

    void AniEventSetFloat(object param)
    {
        if (receiveValueSetEvent)
        {
            object[] ps =( object[]) param;
            animator.SetFloat((string)ps[0], (float)ps[1]);
        }
    }

    void AniEventSetBool(object param)
    {
        if (receiveValueSetEvent)
        {
            object[] ps = (object[])param;
            animator.SetBool((string)ps[0], (bool)ps[1]);
        }
    }

    void AniEventSetInt(object param)
    {
        if (receiveValueSetEvent)
        {
            object[] ps = (object[])param;
            animator.SetInteger((string)ps[0], (int)ps[1]);
        }
    }


}
